package com.axjy.web;

import com.axjy.pojo.RoleMgn;
import com.axjy.service.RoleMgnService;
import com.axjy.util.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dell on 2018/1/25.
 */
@RestController
public class RoleMgnHandler {

    @Resource
    private RoleMgnService roleMgnService;

    @GetMapping("/search1")
    public List<RoleMgn> search(String customName){
        return roleMgnService.search1(customName);
    }

    @PostMapping("/add")
    public String add(RoleMgn roleMgn){
        String msg = null;
        try{
            roleMgnService.add(roleMgn);
            msg="新增成功";
        }catch (RuntimeException ex){
            msg="新增失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

    @PostMapping("/update")
    public String update(RoleMgn roleMgn){
        String msg = null;
        try{
            roleMgnService.update(roleMgn);
            msg="修改成功";
        }catch (RuntimeException ex){
            msg="修改失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

    @PostMapping("/delete")
    public String delete(Integer id){
        String msg = null;
        try{
            msg="删除成功";
            roleMgnService.delete(id);
        }catch (RuntimeException ex){
            msg="删除失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
}
